<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

      class Queueelement{   
           constructor(value,key){
               this.value = value;
               this.key = key;
           }
      }

      class Priorityqueue{
          constructor(){    
              this.item = []
          }    
                 
          // 队列尾部添加
          enquqe(v,k){  
            let option = new Queueelement(v,k);
            if(this.item.length== 0){
               this.item.push(option)
            }else{ 
                 let isBig = false
                 for(let i=0;i<this.item.length;i++){
                     if(this.item[i].key > option.key){
                        this.item.splice(i,0,option)
                        break;
                     }
                     isBig = true;
                 }

                 if(isBig == true){
                    this.item.push(option)
                 }  

            }
          }
          // 队列前面删除
          dequqe(){
             return this.item.shift()
          }
          
          // 返回队列第一个元素
          front(){
              return this.item[0];
          }

          isEmpty(){
            return this.item.length == 0
          }

          size(){
            return this.item.length  
          }

          toString(){
             return this.item.join("-")
          }
      }

      let a = new Priorityqueue();
          a.enquqe("小明",1)
          a.enquqe("小明",10)
          a.enquqe("夏红",0)
          a.enquqe("小明",-5)
          a.enquqe("小明",-554)
        

      console.log(a)
       





    </script>
    
</body>
</html>